package com.demo.controller;


import com.demo.service.FeginClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;


@Controller
@EnableAutoConfiguration
public class TestController {

	@Autowired
    private RestTemplate restTemplate;

    @Autowired
    private FeginClient feginClient;

    private final static Logger logger = LoggerFactory.getLogger(TestController.class);

    @RequestMapping("/getText")
    @ResponseBody
    public String getUser() {

        //方法一：调用远程服务
		ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://demo-provider/getText", String.class);
        logger.info("res="+JSON.toJSONString(responseEntity));


        //方法二：通过Fegin来调用 推荐
        String result=feginClient.getText();
        logger.info("res=" + JSON.toJSONString(result));
        return "";
    }

}